#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

unsigned int Mystrlen(const char* s)
{
	assert(s);
	int count = 0;
	while (*s != '\0')
	{
		count++;
		s++;
	}

	return count;
}

char* Mystrcpy(char* dest, const char* src)
{
	assert(dest && src);

	char* ret = dest;
	while (*dest++ = *src++)
	{
		;
	}

	return ret;
}

int Mystrcmp(const char* dest, const char* src)
{
	assert(dest && src);
	int ret = 0;
	while (!(ret = *(unsigned char*)dest - *(unsigned char*)src) && *src)
	{
		dest++;
		src++;
	}

	return ret;
}

char* Mystrcat(char * dest, const char * src)
{
	assert(dest && src);
	char* ret = dest;

	while (*dest++)
	{
		;
	}
	dest--;

	while (*dest++ = *src++)
	{
		;
	}

	return ret;
}

char* Mystrstr(const char* dest, const char* src)
{
	assert(dest && src);

	const char* cur1 = dest;
	const char* cur2 = src;
	const char* str1 = dest;
	const char* str2 = src;

	while (*cur1 != '\0')
	{
		if (*cur1 == *cur2)
		{
			str1 = cur1;
			str2 = cur2;
			while (*str2 && (*str1++ == *str2++))
			{
				;
			}
			if (*str2 == '\0')
			{
				return cur1;
			}
			
		}
		cur1++;
	}
	return NULL;
}

int main()
{
	char c1[50] = "BBCDBB";
	char c2[20] = "BCDB";
	int ret = Mystrlen(c1);
	printf("%d\n", ret);
	printf("%s\n", Mystrstr(c1, c2));
	return 0;
}